﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;

namespace Client
{
    public partial class FormVipPayOrder : BaseChildForm
    {

        QunYing.BLL.VipPayOrder bll_payOrder = new QunYing.BLL.VipPayOrder();
        public FormVipPayOrder()
        {
            InitializeComponent();
            this.BindData();

            this.sharpGrid1.RowDoubleClickEvent += new EventHandler<Spore.Controls.RowDoubleClickEventArg>(sharpGrid1_RowDoubleClickEvent);
        }

        void sharpGrid1_RowDoubleClickEvent(object sender, Spore.Controls.RowDoubleClickEventArg e)
        {
            DataRow dr = this.GetRow();
            if (dr == null) return;
            DataTable dt = dr.Table.Clone();
            dt.ImportRow(dr);
            var model = this.bll_payOrder.DataTableToList(dt)[0];
            FormVipDeferReqLook fvrl = new FormVipDeferReqLook();
            fvrl.BindData(model);
            fvrl.ShowDialog();
        }

        private DataRow GetRow()
        {
            GridView view = this.sharpGrid1.MainView as GridView;
            int[] rows = view.GetSelectedRows();
            if (rows.Length == 0)
                return null;
            foreach (var v in rows)
            {
                if (v < 0)
                    continue;
                DataRowView rowView = view.GetRow(v) as DataRowView;
                if (rowView == null)
                    return null;
                return rowView.Row;
            }
            return null;

        }

        public override void BindData()
        {
            if (GlobalInfo.UserLoginInfo.角色 != "经销商")
            {
                this.sharpGrid1.DataSource = bll_payOrder.GetAllList().Tables[0];
            }
            else
            {
                this.sharpGrid1.DataSource = bll_payOrder.GetList(string.Format("经销商ID='{0}'", GlobalInfo.UserLoginInfo.用户ID)).Tables[0];
                
            }
        }
    }
}
